package com.ruoyi.rocky.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.rocky.domain.PcExamine;
import com.ruoyi.rocky.domain.PcVehicles;
import com.ruoyi.rocky.domain.PcVehiclesJoin;
import com.ruoyi.rocky.service.PcVehiclesService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 车辆信息Controller
 * @date 2024-04-25
 */
@RestController
@RequestMapping("/pcVehicles")
@Api(tags = "车辆管理")
public class PcVehiclesController extends BaseController {
    @Autowired
    private PcVehiclesService pcVehiclesService;

    /**
     * 查询车辆信息列表
     */
    @ApiOperation(value = "查询车辆信息列表")
    @GetMapping("/list")
    public TableDataInfo list(PcVehicles pcVehicles) {
        startPage();
        List<PcVehicles> list = pcVehiclesService.selectPcVehiclesList(pcVehicles);
        return getDataTable(list);
    }

//    /**
//     * 导出车辆信息列表
//     */
//    @ApiOperation(value = "导出车辆信息列表")
//    @PostMapping("/export")
//    public void export(HttpServletResponse response, PcVehicles pcVehicles) {
//        List<PcVehicles> list = pcVehiclesService.selectPcVehiclesList(pcVehicles);
//        ExcelUtil<PcVehicles> util = new ExcelUtil<PcVehicles>(PcVehicles.class);
//        util.exportExcel(response, list, "车辆信息数据");
//    }

    /**
     * 根据车辆id获取车辆信息
     */
    @ApiOperation(value = "根据车辆id获取车辆信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(pcVehiclesService.selectPcVehiclesById(id));
    }

    /**
     * 车辆申请
     */
    @ApiOperation(value = "车辆申请")
    @PostMapping
    public R<Boolean> add(@RequestBody PcVehiclesJoin pcVehiclesJoin) {
        return pcVehiclesService.insertPcVehicles(pcVehiclesJoin);
    }

    @ApiOperation(value = "车辆审核")
    @PostMapping(value = "/examineVehicles")
    public R examineStore(@RequestBody PcExamine dto) {
        return pcVehiclesService.examineStore(dto);
    }

    /**
     * 修改车辆信息
     */
    @ApiOperation(value = "修改车辆信息")
    @PutMapping
    public R<Boolean> edit(@RequestBody PcVehicles pcVehicles) {
        return pcVehiclesService.updatePcVehicles(pcVehicles);
    }

    /**
     * 删除车辆信息
     */
    @ApiOperation(value = "删除车辆信息")
    @DeleteMapping("/{ids}")
    public R<Boolean> remove(@PathVariable Long[] ids) {
        return pcVehiclesService.deletePcVehiclesByIds(ids);
    }
}

